package demoMod.nanaki.cards.nanaki;

import com.badlogic.gdx.graphics.Color;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.vfx.combat.WhirlwindEffect;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.actions.BurialAction;
import demoMod.nanaki.actions.XCostAction;
import demoMod.nanaki.powers.NotePower;

import java.util.stream.Collectors;

public class SharpSound extends AbstractNanakiCard {
    public static final String ID = NanakiMod.makeID("SharpSound");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/SharpSound";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.ALL_ENEMY;

    private static final int COST = -1;

    public SharpSound() {
        super(ID, NAME, NanakiMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.baseMagicNumber = this.magicNumber = 4;
        this.exhaust = true;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> upgradeMagicNumber(3);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new XCostAction(this, effect -> {
            for (int i=0;i<effect;i++) {
                for (AbstractMonster mo : AbstractDungeon.getCurrRoom().monsters.monsters.stream().filter(monster -> !monster.isDeadOrEscaped()).collect(Collectors.toList())) {
                    addToTop(new ApplyPowerAction(mo, p, new NotePower(mo, this.magicNumber)));
                }
            }
            if (effect > 0) {
                addToTop(new VFXAction(new WhirlwindEffect(Color.CHARTREUSE, false), 0.0F));
                addToTop(new BurialAction(effect));
            }
        }, this.energyOnUse));
    }
}
